package com.eleadmin.store.service.impl;

import com.eleadmin.damon.utils.results.PageResult2;
import com.eleadmin.common.core.web.JsonResult;
import com.eleadmin.common.system.entity.User;
//import com.eleadmin.store.mapper.ProductMapper;
import com.eleadmin.store.entity.Product;
import com.eleadmin.store.service.ProductService;
import org.springframework.stereotype.Service;
import com.eleadmin.store.biz.ProductBiz;
import net.sf.json.JSONObject;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
//import javax.transaction.Transactional;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 产品管理服务实现类
 * @author : Doman
 * @date : 2024-02-13 18:39:57
 * @version ：1.0
 */
@Service
public class ProductServiceImpl /*extends ServiceImpl<ProductMapper, Product> */implements ProductService {

    @Autowired
    private ProductBiz productBiz;

    @Override
    public JsonResult list(PageResult2<T> page, Product product, User loginUser)  throws Exception{
        return productBiz.list(page,product,loginUser);
    }

    @Override
    public JsonResult list(Product product, User loginUser) {
        return JsonResult.ok().setData(productBiz.list(product,loginUser));
    }

    @Override
    public JsonResult listSel(Product product, User loginUser) {
        return JsonResult.ok().setData(productBiz.listSel(product,loginUser));
    }

    @Override
    public JsonResult listSelUnique(Product product, User loginUser) {
        return JsonResult.ok().setData(productBiz.listSelUnique(product,loginUser));
    }

    @Override
    public JsonResult getById(String id) {
        return JsonResult.ok().setData(productBiz.getById(id));
    }

    @Transactional
    @Override
    public JsonResult save(Product product, User loginUser) {
        if (productBiz.save(product, loginUser)) {
            return JsonResult.ok("添加成功");
        }
        return JsonResult.error("添加失败");
    }

    @Transactional
    @Override
    public JsonResult update(Product product, User loginUser) {
        if (productBiz.update(product, loginUser)) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }

    @Transactional
    @Override
    public JsonResult remove(String id, User loginUser) {
        if (productBiz.remove(id, loginUser)) {
            return JsonResult.ok("删除成功");
        }
        return JsonResult.error("删除失败");
    }

}
